package com.scott.classicthreadmodal.demo2.producer;

import com.scott.classicthreadmodal.demo2.storage.IStorage;

/**
 * 生产者
 */
public class Producer implements Runnable {

    /**
     * 生产者名称
     */
    private String name;

    /**
     * 生产数量
     */
    private int num;

    private IStorage storage;

    public Producer(String name, int num, IStorage storage) {
        this.name = name;
        this.num = num;
        this.storage = storage;
    }



    /**
     * 生产
     */
    @Override
    public void run() {
        try {
            while (true) {

                System.out.printf("%s:%s准备生产\n", Thread.currentThread().getName(),this.name);
                storage.produce(getNum(),getName());
                System.out.printf("%s:%s生产完成\n", Thread.currentThread().getName(),this.name);
                System.out.println("===============");
                Thread.sleep(2000);

            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public IStorage getStorage() {
        return storage;
    }

    public void setStorage(IStorage storage) {
        this.storage = storage;
    }
}
